<#assign basePath=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <title>登录</title>
    <link href="${basePath}/css/login.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="page-container">
    <div class="formStyle">
        <form id="_form" action="" method="post">
            <h2>后台登录</h2>
            <input value="admin" type="text" name="account" class="username" placeholder="账号" required>
            <input value="12345" type="password" name="password" class="password" placeholder="密码" required>
            <button type="button" id="login">登 录</button>
            <button type="button" id="register" class="register">注 册</button>
        </form>
    </div>
</div>
<script src="${basePath}/js/jquery1.8.3.min.js"></script>
<script src="${basePath}/js/MD5.js"></script>
<script src="${basePath}/js/layer/layer.js"></script>
<script>
    jQuery(document).ready(function () {
        // try {
        //     var _href = window.location.href + "";
        //     if (_href && _href.indexOf('?kickout') != -1) {
        //         layer.msg('您已经被踢出，请重新登录！');
        //     }
        // } catch (e) {
        //
        // }
        //回车事件绑定

        //解决登录嵌套的问题
        if (window.parent != window) {
            window.parent.location.reload(this);
        }

        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                $('#login').click();
            }
        };

        //登录操作
        $('#login').click(function () {
            var username = $('.username').val();
            var password = $('.password').val();

            if(username==''||password==''){
                layer.msg("用户名和密码不能为空");
                return false;
            }

            var pswd = MD5(username + "#" + password),
                    data = {pswd: pswd, email: username, rememberMe: $("#rememberMe").is(':checked')};
            var load = layer.load();

            $.ajax({
                url: "${basePath}/user/submitLogin",
                data: data,
                type: "post",
                dataType: "json",
                success: function (result) {
                    layer.close(load);
                    if (result && result.status != 200) {
                        layer.msg(result.message, function () {
                        });
                        $('.password').val('');
                        return;
                    } else {
                        layer.msg('登录成功！');
                        setTimeout(function () {
                            //登录返回
                            window.location.href = result.back_url || "${basePath}/";
                        }, 1000)
                    }
                },
                error: function (e) {
                    console.log(e, e.message);
                    layer.msg('请看后台Java控制台，是否报错，确定已经配置数据库和Redis', new Function());
                }
            });
        });
        //注册
        $("#register").click(function () {
            window.location.href = "register.shtml";
        });
    });
</script>
</body>
</html>